<!--
 * @Author: Bennty
 * @Date: 2024-09-03 10:16:05
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-09-05 15:41:12
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" title="系统提示" width="20%" @close="handleClose">
        <h3>请选择转公海理由：</h3>
        <el-radio-group v-model="reason">
            <el-radio v-for="item in props.reason" :key="item.value" :label="item.label" >{{ item.label }}</el-radio>
        </el-radio-group>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleSubmit">确 定</el-button>
                <el-button @click="handleClose">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';

import { toSeaApi } from '@/api/sj/customer-crm/index';

const form = ref<FormInstance>();
const props = defineProps(['visible','data','reason']);
const emit = defineEmits(['submit','close']);
const reason = ref('');
const handleClose = ()=>{
    form.value?.resetFields();
    emit('close');
};

const handleSubmit = async ()=>{
    const submitData = {
        id: props.data.id,
        toSeaReason: reason.value
    };
    await toSeaApi(submitData).then((result)=>{
        if(result.code == 200){
            handleClose()
            emit('submit',true);
        }else{
            emit('submit',false);
        }
    }).catch((error)=>{
        emit('submit',false);
    });
};


</script>

<style lang="scss" scoped>
.dialog-footer{
    display:flex;
    justify-content: center;
}
</style>